"use strict"

class this.DropableList

  constructor: (options) ->
    @list = []

  clear: () ->
    @list = []

  add: (shape) ->
    shape.settings.droptarget && @list.push shape
    @

  remove: (shape) ->
    if (idx = @list.indexOf(shape)) >= 0
      @list.splice idx, 1
    @

  findTarget: (shape, ex) ->
    ary = _.filter @list, (e) ->
      e != shape && (shape.settings.dropable && shape.settings.dropable[e.settings.type] || e.settings.type == 'trash') && Util.isOverlapping(e.getExtent(), ex)
    _.last(ary)

  highlightTarget: (target, child) ->
    _.each @list, (e) -> e != target && e.resetDropTarget()
    target && target.setDropTarget(child)
    @
